<?php


require_once( "_inc.php" );
if ( "db" == $_GET['action'] && !empty( $_GET['file'] ) )
{
	$dataDir = "../#data/db/";
	$filename = basename( $_GET['file'] );
	$file = $dataDir.$filename;
	if ( !file_exists( $file ) )
	{
		$tpl->assign( "msg", "文件不存在。" );
		$tpl->assign( "backUrl", "db_import.php" );
		$tpl->display( "_msg.tpl" );
		exit( );
	}
	$fileSize = filesize( $file );
	header( "Content-type: application/octet-stream" );
	header( "Accept-Ranges: bytes" );
	header( "Content-Length: ".$fileSize );
	header( "Content-Disposition: attachment; filename=".$filename );
	$fp = fopen( $file, "r" );
	$bufferSize = 1024;
	$curPos = 0;
	while ( !feof( $fp ) || $bufferSize < $fileSize - $curPos )
	{
		$buffer = fread( $fp, $bufferSize );
		echo $buffer;
		$curPos += $bufferSize;
	}
	$buffer = fread( $fp, $fileSize - $curPos );
	echo $buffer;
}
?>
